home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / TEMP / GNU / bison / BisonParse < prev    next >
Text File  |  1995-06-28  |  2KB  |  45 lines

  1. Bison Parser
  2. Previous: <Semantic Actions=>SemanticAc> * Next: <Stages=>Stages> * Up: <Concepts=>Concepts>
  3.  
  4. #Wrap on
  5. {fH3}Bison Output: the Parser File{f}
  6.  
  7. When you run Bison, you give it a Bison grammar file as input.  The output
  8. is a C source file that parses the language described by the grammar.
  9. This file is called a {fUnderline}Bison parser{f}.  Keep in mind that the Bison
  10. utility and the Bison parser are two distinct programs: the Bison utility
  11. is a program whose output is the Bison parser that becomes part of your
  12. program.
  13.  
  14. The job of the Bison parser is to group tokens into groupings according to
  15. the grammar rules---for example, to build identifiers and operators into
  16. expressions.  As it does this, it runs the actions for the grammar rules it
  17. uses.
  18.  
  19. The tokens come from a function called the {fUnderline}lexical analyzer{f} that you
  20. must supply in some fashion (such as by writing it in C).  The Bison parser
  21. calls the lexical analyzer each time it wants a new token.  It doesn't know
  22. what is ``inside'' the tokens (though their semantic values may reflect
  23. this).  Typically the lexical analyzer makes the tokens by parsing
  24. characters of text, but Bison does not depend on this.  \*Note <Lexical=>Lexical>: The Lexical Analyzer Function {fCode}yylex{f}.
  25.  
  26. The Bison parser file is C code which defines a function named
  27. {fCode}yyparse{f} which implements that grammar.  This function does not make
  28. a complete C program: you must supply some additional functions.  One is
  29. the lexical analyzer.  Another is an error-reporting function which the
  30. parser calls to report an error.  In addition, a complete C program must
  31. start with a function called {fCode}main{f}; you have to provide this, and
  32. arrange for it to call {fCode}yyparse{f} or the parser will never run.
  33. \*Note <Interface=>Interface>: Parser C-Language Interface.
  34.  
  35. Aside from the token type names and the symbols in the actions you
  36. write, all variable and function names used in the Bison parser file
  37. begin with {fEmphasis}yy{f} or {fEmphasis}YY{f}.  This includes interface functions
  38. such as the lexical analyzer function {fCode}yylex{f}, the error reporting
  39. function {fCode}yyerror{f} and the parser function {fCode}yyparse{f} itself.
  40. This also includes numerous identifiers used for internal purposes.
  41. Therefore, you should avoid using C identifiers starting with {fEmphasis}yy{f}
  42. or {fEmphasis}YY{f} in the Bison grammar file except for the ones defined in
  43. this manual.
  44.  
  45.